package com.wangcanxuan.www.util.logging;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

/**
 * 日志输出格式
 *
 * @author HHLJ
 * @date 2022/03/17
 */
public class MyFormat extends Formatter {
    /**
     * 给我的日志定义的输出格式，包括时间，日志等级，内容，所在位置，所在方法等
     *
     * @param record 记录
     * @return {@link String}
     */
    @Override
    public String format(LogRecord record) {
        // 默认时区
        ZonedDateTime zonedDateTime = ZonedDateTime.now();
        String nowDate = zonedDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return  "[" + nowDate + "] " + " [" + record.getLevel().getName() + "] " +  " [" + Thread.currentThread().getName() + "] "
                + " at " + record.getSourceClassName() + "." + record.getSourceMethodName()
                + " " + record.getMessage() + "\n";
    }
}
